package com.xiaoma.tpo.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.TUser;
import com.xiaoma.tpo.dto.TUserRoleRightVO;
@Repository
public class TUserDao extends BaseDaoImpl<TUser>{

	public void delete(Integer id) {
		String sql = "delete from t_user where id = "+id;
		jdbcTemplate.execute(sql);
		
	}

	public List<Object> findUserRoleRightByUsername(String username) {
		if(username != null){
			String sql = " select distinct tr.id as id ,tr.parent_id as p_id,null as menuid ,'' as icon ,tr.right_name as menuname ,tr.url ,null as menus"
					+ " from t_user tu , t_user_role tur , t_role_right trr , t_right tr "
					+ " where tu.id = tur.user_id and tur.role_id = trr.role_id and trr.right_id = tr.id and username='"+username+"' "
					+ " order by tr.id";
			List<Object> obj = jdbcTemplate.query(sql, new DefaultRowMapper(TUserRoleRightVO.class,this.getNameHandler()));
			return obj;
		}else{
			return null;
		}
		
	}

}
